package com.shop.adTag;

import com.shop.advertisement.service.IndexRecommendAdService;
import com.shop.annotation.BeetlTagName;
import com.shop.pojo.LdbzIndexRecommendAd;
import org.beetl.core.GeneralVarTagBinding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Scope("prototype")
@BeetlTagName("index_recommend_tag")
public class IndexRecommendTag extends GeneralVarTagBinding {
    private static Logger logger = LoggerFactory.getLogger(IndexRecommendTag.class);
    @Autowired
    private IndexRecommendAdService indexRecommendAdService;

    @Override
    public void render() {
        Object site = this.getAttributeValue("site");
        logger.debug("获取首页推荐广告");
        List<LdbzIndexRecommendAd> byRedis = indexRecommendAdService.getIndexRecommendAdByRedis();
        for (LdbzIndexRecommendAd entity : byRedis) {
            if (entity.getAdKey().equals(byRedis)) {
                this.binds(entity);
                this.doBodyRender();
            }
        }
    }
}
